//
//  HomeController.m
//  NavigationDemo
//
//  Created by 商广硕 on 2022/7/1.
//

#import "HomeController.h"
#import "ListViewController.h"
#import "DHLsitViewController.h"
#import "MyView.h"
#import "DHQrCoceViewController.h"
#import "DHScanViewController.h"
#import "DHPickerVC.h"
#import "iconfontViewController.h"
@interface HomeController ()

@end

@implementation HomeController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //隐藏导航栏
    self.isHidden=YES;
   
    
  //自定义按钮
    [self setButton];
    //扫一扫
    [self scanBtn];
    
    
    MyView* view = [MyView myView];
    view.backgroundColor = [UIColor redColor];
//    view.frame = CGRectMake(0, 0, 300, 100);
    view.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2);
    [self.view addSubview:view];
    
 
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark -自定义按钮
-(void) setButton{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(30, 100, 90, 88);
    [btn setTitle:@"自定义Cell" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
//    [btn setImage:[UIImage imageNamed:@"image_face_eye"] forState:(UIControlStateNormal)];
    // 默认的是图片在左title 在右
        // 1,图片在右边,title 在左边 可以调左边距 也可以调右边距
    //    button.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,-150);// 和(0,150,0,0) 一样效果
    //    button.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0,50); // (0,-50,0,0) 一样效果
        // 2 图片在上 title 在下面 // 具体数字可以自己调
//    btn.imageEdgeInsets = UIEdgeInsetsMake(- 20,50,0,0);
//    btn.titleEdgeInsets = UIEdgeInsetsMake(32, 0, 0,0);

   
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

   ///设置边框
    if (@available(iOS 11.0, *)) {
        btn.layer.maskedCorners = kCALayerMinXMinYCorner |kCALayerMaxXMinYCorner|kCALayerMinXMaxYCorner |kCALayerMaxXMaxYCorner; // 设置哪些角为圆角

    } else {
        // Fallback on earlier versions
    }
//    btn.backgroundColor=[UIColor redColor];

    btn.layer.borderWidth=1;
    btn.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor blueColor]);
    btn.layer.cornerRadius = 16;
    btn.backgroundColor=[UIColor redColor];
  
    [self.view addSubview:btn];
    btn.tag=1;
    [btn  addTarget:self action:@selector(onClickBtn:) forControlEvents:UIControlEventTouchUpInside];

    
    UIView *vew = [[UIView alloc]init];
    vew.frame=CGRectMake(150,100, 40, 40);
    vew.layer.cornerRadius = 20;
    vew.layer.masksToBounds = YES;
    vew.backgroundColor = [UIColor purpleColor];
    //创建手势=点击事件
    UITapGestureRecognizer *g= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onViewClick)];
    //添加手势
    [vew  addGestureRecognizer:g];
    [self.view addSubview:vew];
   
}
-(void) scanBtn{
    UIButton *scanBtn = [UIButton buttonWithType:UIButtonTypeCustom ] ;
    scanBtn.frame= CGRectMake(200, 100, 70, 40);
    [scanBtn setTitle:@"扫一扫" forState:UIControlStateNormal];
    [scanBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    scanBtn.backgroundColor = [UIColor purpleColor];
    scanBtn.tag =2;
    [scanBtn addTarget:self action:@selector(onClickBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:scanBtn];
    
    
}

-(void)onViewClick{

    DHQrCoceViewController *qrCodeVC= [[DHQrCoceViewController alloc] init];
    [self.navigationController pushViewController:qrCodeVC animated:YES ];
}
- (IBAction)onClick:(id)sender {
    ListViewController *listVC =[[ListViewController alloc] init];
    [self.navigationController pushViewController:listVC animated:YES];
}
- (IBAction)aLiClick:(id)sender {
    [self.navigationController pushViewController:[[iconfontViewController alloc] init] animated:YES ];
}
-(IBAction)onClickBtn:(UIButton *)button{
    NSLog(@"%@ tag%ld",button ,(long)button.tag);
    if (button.tag == 1) {
        DHLsitViewController *dhList= [[DHLsitViewController alloc] init];
        [self.navigationController pushViewController:dhList animated:YES ];
    }else if(button.tag == 2)
    {
        DHScanViewController *scanVC= [[DHScanViewController alloc] init];
        [self.navigationController pushViewController:scanVC animated:YES ];
    }
}

- (IBAction)onPicker:(id)sender {
    DHPickerVC *VC= [[DHPickerVC alloc] init];
    [self.navigationController pushViewController:VC animated:YES ];
}


@end
